//
//  ShopCarViewController.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/8.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "ShopCarViewController.h"
#import "ShopCarViewModel.h"
#import "CheckGoodsInforViewController.h"

@interface ShopCarViewController ()<ShopCarDeleagte>{
    UIButton * btn;
    BOOL selectBool;
}
@property (nonatomic,strong) ShopCarViewModel * shopCarViewModel;
@end

@implementation ShopCarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    selectBool = NO;
    if (self.controllerCount == 1) {
        CGFloat t_height;
        if (iPhoneX) {
            t_height = 83 - kHeightProportion_In_iPhoneTriploid(34);
        }else{
            t_height = 49;
        }
        self.groupedTableView.height = self.groupedTableView.height - t_height;
    }else{
        self.title = @"购物车";
    }
    self.shopCarViewModel = [[ShopCarViewModel alloc] initWithViewToViewModel:self.groupedTableView theSuperView:self.view];
    [self headerRereshing];
    self.shopCarViewModel.delegate =self;
    //
    btn = [UIButton buttonWithType:UIButtonTypeSystem];
    btn.frame = CGRectMake(0, 0, 30, 20);
    [btn setTitle:@"编辑" forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(editAction) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = SYSTEMFONT(15);
    [btn setTitleColor:kColor_Rule_Yellow forState:UIControlStateNormal];
    [btn sizeToFit];
    UIBarButtonItem * item = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.rightBarButtonItem = item;
}

-(void)headerRereshing{
    [self.shopCarViewModel shopCarRequestData];
}


-(void)editAction{
    selectBool = !selectBool;
    if (selectBool) {
        [btn setTitle:@"完成" forState:UIControlStateNormal];
    }else{
        [btn setTitle:@"编辑" forState:UIControlStateNormal];
    }
    self.shopCarViewModel.editBool = selectBool;
}

#pragma maek -- ShopCarDeleagte
-(void)selectJieSuang:(NSMutableArray *)shopCarGoodsArr{
    DLog(@"%@",shopCarGoodsArr);
    CheckGoodsInforViewController * checkGoodsVC = [CheckGoodsInforViewController new];
    checkGoodsVC.g_Arr = shopCarGoodsArr;
    [self.navigationController pushViewController:checkGoodsVC animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
